
var ttt6 = "#fUI/UIWindow.img/PvP/Scroll/enabled/next2#";
var time = new Date();
var hour = time.getHours(); //獲得小時
var minute = time.getMinutes(); //獲得分鐘
var second = time.getSeconds(); //獲得秒
var Year = time.getFullYear();
var month = time.getMonth() + 1; //獲取当前月份(0-11,0代表1月)
var dates = time.getDate(); //獲取当前日(1-31)
var status = -1;
var rand = 0;
var InsertData = false;
var nx = false;
var nxx = false;
var price = 250000;
var priceD = 8;
var debug = true;



/*以下為要修改的*/
var rates = [10000,60000,430000,500000];//總共100萬 最好->最差

//物品代碼 數量 時間期限(沒有就0)  只有Advanced會廣播
var itemListAdvanced = Array(
    Array(2431561, 1, 0), //高级冒險島勇士之心(战士)
	Array(1052671, 1, 0), //大號睡衣
	Array(1702488, 1, 0),//邦尼的胡萝卜
	Array(1102787, 1, 0),//调查兵团披风
	Array(1073150, 1, 0),//蛋黄拖
	Array(1004916, 1, 0),//超星魔导帽子(台灣之光)
	Array(3015481, 1, 0),//轻功箱椅子
	Array(3015157, 1, 0)//安德洛墨达椅子
	
);
var itemListGold = Array(
	Array(4033667, 1, 0),//意志盒
	Array(1112915, 1, 0),//蓝调戒指
	Array(1122224, 1, 0), //心之项链链子
	Array(2431556, 1, 0), //冒險島勇士之心(战士)
	Array(1003622, 1, 0), //布莱克缤帽 
	Array(1003621, 1, 0), //混沌品克缤帽 
	Array(1003780, 1, 0), //自由品克缤帽 
	Array(1003781, 1, 0), //自由布莱克缤帽 
	Array(1052526, 1, 0), //混沌品克缤大衣 
	Array(1052527, 1, 0), //布莱克缤大衣 
	Array(1052588, 1, 0), //自由品克缤連身衣 
	Array(1052589, 1, 0), //自由布莱克缤連身衣 
	Array(1212072, 1, 0), //布莱克缤双头杖 
	Array(1222067, 1, 0), //布莱克缤灵魂手铳 
	Array(1232064, 1, 0), //布莱克缤亡命剑 
	Array(1242069, 1, 0), //布莱克缤能量剑 
	Array(1242070, 1, 0), //布莱克缤能量剑 
	Array(1302070, 1, 0), //布莱克缤单手剑 
	Array(1312142, 1, 0), //布莱克缤单手斧 
	Array(1322100, 1, 0), //布莱克缤单手钝器 
	Array(1332214, 1, 0), //布莱克缤短刀 
	Array(1342079, 1, 0), //布莱克缤双刀 
	Array(1362081, 1, 0), //布莱克缤手杖 
	Array(1372168, 1, 0), //布莱克缤短杖 
	Array(1382199, 1, 0), //布莱克缤长杖 
	Array(1402185, 1, 0), //布莱克缤双手剑 
	Array(1412126, 1, 0), //布莱克缤双手斧 
	Array(1422129, 1, 0), //布莱克缤双手钝器 
	Array(1432158, 1, 0), //布莱克缤长枪 
	Array(1442209, 1, 0), //布莱克缤长矛 
	Array(1452196, 1, 0), //布莱克缤弓 
	Array(1462184, 1, 0), //布莱克缤弩 
	Array(1472205, 1, 0), //布莱克缤拳套 
	Array(1482159, 1, 0), //布莱克缤指节 
	Array(1492170, 1, 0), //布莱克缤短枪 
	Array(1522085, 1, 0), //布莱克缤双弩枪 
	Array(1532089, 1, 0), //布莱克缤火炮 
	Array(3010592, 1, 0), //布莱克缤椅子
	Array(3010071, 1, 0) //神兽椅
);
var itemListSilver = Array(
	Array(5062002,1,0),
	Array(3010013, 1, 0), //悠长假期
	Array(3010014, 1, 0), //月亮弯
	Array(3010018, 1, 0), //椰子树沙滩椅
	Array(3010019, 1, 0), //寿司椅
	Array(3010021, 1, 0), //暖暖桌
	Array(3010025, 1, 0), //枫叶纪念凳
	Array(3010028, 1, 0), //海盗的俘虏
	Array(3010029, 1, 0), //蓝环凳
	Array(3010030, 1, 0), //黑环凳
	Array(3010031, 1, 0), //红环凳
	Array(3010032, 1, 0), //黄环凳
	Array(3010033, 1, 0), //绿环凳
	Array(3010037, 1, 0), //猪猪凳
	Array(3010044, 1, 0), //同一红伞下
	Array(3012001, 1, 0), //篝火
	Array(3012002, 1, 0), //浴桶
	Array(3010073, 1, 0), //PB克缤
	Array(3012003, 1, 0), //爱心椅子
	Array(3010012, 1, 0), //剑士 宝座
	Array(3010025, 1, 0), //枫叶纪念凳
	Array(3010037, 1, 0), //猪猪凳
	Array(3010038, 1, 0), //爱心椅子
	Array(3010040, 1, 0), //蝙蝠椅
	Array(3010041, 1, 0), //骷髅王座
	Array(3010043, 1, 0), //魔女的飞扫把
	Array(3010044, 1, 0), //同一红伞下
	Array(3010045, 1, 0), //寒冰椅子
	Array(3010046, 1, 0), //红龙椅
	Array(3010047, 1, 0), //蓝龙椅
	Array(3010048, 1, 0), //圣诞树椅子
	Array(3010049, 1, 0), //雪房子
	Array(3010050, 1, 0), //公主凳
	Array(3010057, 1, 0), //血色玫瑰
	Array(3010058, 1, 0), //世界末日
	Array(3010068, 1, 0), //露水椅子
	Array(1032032, 1, 0), //秋叶耳环
	Array(1032035, 1, 0), //枫叶耳环
	Array(1032040, 1, 0), //枫叶型耳环,800,1,0), //初
	Array(1032041, 1, 0), //枫叶型耳环,800,1,0), //庆
	Array(1032042, 1, 0), //枫叶型耳环,800,1,0), //盛
	Array(1032055, 1, 0), //工作人员C的旧收信机
	Array(1032056, 1, 0), //工作人员C的旧收信机
	Array(1032057, 1, 0), //工作人员C的旧收信机
	Array(1032058, 1, 0), //工作人员C钛质收信机
	Array(1122001, 1, 0), //绿色蝶形領结
	Array(1122002, 1, 0), //红色蝶形領结
	Array(1122003, 1, 0), //黄色蝶形領结
	Array(1122004, 1, 0), //粉红蝶形領结
	Array(1122005, 1, 0), //黑色蝶形領结
	Array(1122006, 1, 0), //蓝色蝶形領结
	Array(1122015, 1, 0), //枫叶围巾
	Array(1122058, 1, 0), //休彼德蔓的混沌项链
	Array(1132000, 1, 0), //白色腰带
	Array(1132001, 1, 0), //黄色腰带
	Array(1132002, 1, 0), //蓝色腰带
	Array(1132003, 1, 0), //红色腰带
	Array(1132004, 1, 0), //黑贺腰带
	Array(1132010, 1, 0), //黄金猪猪腰带
	Array(1132011, 1, 0), //黄金猪猪腰带
	Array(1132012, 1, 0), //法老的腰带
	Array(1132013, 1, 0), //不灭的法老腰带
	Array(1122074, 1, 0), //枫叶吊坠
	Array(1122075, 1, 0), //黄金枫叶魔法吊坠
	Array(1002390, 1, 0), //真扎昆头盔
	Array(1002391, 1, 0), //海盗头巾(绿)
	Array(1002392, 1, 0), //海盗头巾(红)
	Array(1002393, 1, 0), //海盗头巾(粉)
	Array(1002394, 1, 0), //海盗头巾(灰)
	Array(1002395, 1, 0), //海盗头巾(紫)
	Array(1002418, 1, 0), //废报纸头盔
	Array(1002419, 1, 0), //枫叶帽
	Array(1002424, 1, 0), //红马術帽
	Array(1002425, 1, 0), //蓝马術帽
	Array(1002441, 1, 0), //热血头带
	Array(1002508, 1, 0), //枫叶头盔
	Array(1002509, 1, 0), //枫叶头盔
	Array(1002510, 1, 0), //枫叶头盔
	Array(1002511, 1, 0), //枫叶头盔
	Array(1002547, 1, 0), //红猎人帽子
	Array(1002550, 1, 0), //黑色格莱西头盔
	Array(1002551, 1, 0), //蓝龙头盔
	Array(1002554, 1, 0) //武艺头绳
);
var itemListNormal = Array(
	//------手套------
	Array(1082145, 1, 0), //工地手套(黄)
	Array(1082146, 1, 0), //工地手套(红)
	Array(1082147, 1, 0), //工地手套(蓝)
	Array(1082148, 1, 0), //工地手套(紫)
	Array(1082149, 1, 0), //工地手套(褐)
	Array(1082150, 1, 0), //工地手套(灰)
	Array(3010077, 1, 0), //猫头鹰椅子
	Array(3010085, 1, 0), //鬼娃娃椅子
	Array(3010096, 1, 0), //恐龙化石宝座
	Array(3010095, 1, 0), //石头人座椅
	Array(3010094, 1, 0), //漂漂猪椅子
	Array(3010098, 1, 0), //电视宅人
	Array(3010106, 1, 0), //雪狼战椅
	Array(3010112, 1, 0), //情书柜子
	Array(3010117, 1, 0), //魔法书椅子
	Array(3010119, 1, 0), //羊羊椅子
	Array(3010120, 1, 0), //彩蛋篮子
	Array(3010123, 1, 0), //夏日花朵
	Array(3010124, 1, 0), //都纳斯喷气椅子
	Array(3010125, 1, 0), //尼贝隆战舰椅
	Array(3010127, 1, 0), //扎昆宝座
	Array(3012001, 1, 0), //篝火
	Array(3010136, 1, 0), //6周年怪物王座
	Array(3010155, 1, 0), //暗影双刀的猫头鹰椅子
	Array(3010144, 1, 0), //七夕椅子
	Array(3010149, 1, 0), //猫咪风扇椅
	Array(3010129, 1, 0), //酋长宝座
	Array(3010131, 1, 0), //贪吃熊猫椅
	Array(3010132, 1, 0), //撒娇喵咪椅
	Array(3010133, 1, 0), //帐篷椅
	Array(3010163, 1, 0), //滿月椅
	
	//極致垃圾
	Array(1002002, 1, 0),//金属头盔
	Array(1002003, 1, 0),//钢铁帽
	Array(1002004, 1, 0),//褐色战斗头盔
	Array(1002005, 1, 0),//钢制骑士头盔
	Array(1002007, 1, 0),//铁制头具
	Array(1002009, 1, 0),//钢铁橄榄球帽
	Array(1002011, 1, 0),//钢制海王帽
	Array(1002021, 1, 0),//诺曼头盔
	Array(1002022, 1, 0),//旧诺曼头盔
	Array(1002023, 1, 0),//枪骑士头盔
	Array(1002028, 1, 0),//银制十字军帽子
	Array(1002029, 1, 0),//将军的红头盔
	Array(1002030, 1, 0),//银制战帽
	Array(1050005, 1, 0),//蓝剑道服
	Array(1050011, 1, 0),//黑龙袍
	Array(1050021, 1, 0),//蓝十字锁子甲
	Array(1051011, 1, 0),//红护身铠甲
	Array(1051000, 1, 0),//钢铁铠甲
	Array(1072046, 1, 0),//黄旅行鞋
	Array(1072047, 1, 0),//蓝旅行鞋
	Array(1072050, 1, 0),//青铜鞋
	Array(1072051, 1, 0),//银战斗鞋
	Array(1072112, 1, 0),//蓝铁头鞋
	Array(1072126, 1, 0),//紫金月鞋
	Array(1072127, 1, 0),//蓝金月鞋
	Array(1072132, 1, 0),//祖母绿将军靴
	Array(1072148, 1, 0),//紫十字鞋
	Array(1072154, 1, 0),//蓝飞魂鞋
	Array(1072155, 1, 0),//紫飞魂鞋
	
	//全職業玩具武器
	Array(1302013, 1, 0),//红色鞭子
	Array(1302014, 1, 0),//旧战剑
	Array(1302016, 1, 0),//黄色雨伞
	Array(1302017, 1, 0),//蓝色雨伞
	Array(1302021, 1, 0),//橡皮榔头
	Array(1302022, 1, 0),//竹刀
	Array(1302024, 1, 0),//废报纸卷
	Array(1302087, 1, 0),//火炬
	Array(1302085, 1, 0),//叉子
	Array(1302084, 1, 0),//火柴
	Array(1302061, 1, 0),//蔓藤鞭子
	Array(1302063, 1, 0)//燃烧的火焰刀
);

function action(mode, type, selection) {
    if (mode == 1) {
        status++;
    } else {
        if (status == 0) {
            cm.dispose();
        }
        status--;
    }
    if (status == 0) {
		if(debug && cm.getPlayer().getGMLevel() < 4){
			cm.sendOk("對不起，正在維護中!");
            cm.dispose();
			return;
		}
		var conn = cm.getConnection();
		var ps = conn.prepareStatement("SELECT * FROM Activity0512 ORDER BY id desc LIMIT 5");
        var RankDataBase = ps.executeQuery();
        var text = ""
        var i = 1;
        text += "#d#e最新抽中大獎消息：#k#n#r\r\n\r\n-----------------------------------------------\r\n";
        while (RankDataBase.next()) {
            text += "#fUI/UIToolTip.img/Item/Equip/Star/Star# #r" + RankDataBase.getString("charName") + "#k 在 #b" + RankDataBase.getString("time") + "#k 抽中 #r" + RankDataBase.getString("itemid") + "#k"
            text += "\r\n"
            i++;
        }
		var ttxt = cm.getPlayer().getGMLevel() > 4?"#L3#【GM測試1百抽】#l":"";
        text += "-----------------------------------------------\r\n#L0##b【抽獎 "+ price +" 抵用券/次】#l #L1##d【獎品預覽】#l\r\n#L2##r【抽獎 "+ priceD +" 贊助點/次】#l#k"+ ttxt +" \r\n\r\n \r\n";
        RankDataBase.close();
		ps.close();
		conn.close();
        cm.sendSimple(text);

    } else if (status == 1) {
        if (selection == 0 || selection == 2) {
			if(cm.getInventory(1).getNextFreeSlot() < 1 || cm.getInventory(2).getNextFreeSlot() < 1 || cm.getInventory(3).getNextFreeSlot() < 1 || cm.getInventory(4).getNextFreeSlot() < 1|| cm.getInventory(5).getNextFreeSlot() < 1)
			{
				cm.sendOk("對不起，您的背包每個欄位至少皆要有一個空位!");
                cm.dispose();
				return;
			}
			var canUse = false;
			if(selection == 0 && cm.getNX(2) >= price)
				canUse = true;
			else if(selection == 2 && cm.getRMB() >= priceD)
				canUse = true;
            var ii = cm.getItemInfo();
            if (canUse) {
                var item;
                var xxx = Math.floor(Math.random() * 1000000);
                if (xxx < rates[0]) {//傳說物品
                    rand = Math.floor(Math.random() * itemListAdvanced.length);
					item = itemListAdvanced[rand];
                    InsertData = true;
                } else if (xxx < rates[1]) {//金牌物品
                    rand = Math.floor(Math.random() * itemListGold.length);
                    item = itemListGold[rand];
                } else if (xxx < rates[2]) {//銀牌物品
                    rand = Math.floor(Math.random() * itemListSilver.length);
                    item = itemListSilver[rand];
                } else {//垃圾
                    rand = Math.floor(Math.random() * itemListNormal.length);
                    item = itemListNormal[rand];
                }
                if (item == -1) {
                    cm.sendOk("對不起，您的背包已經滿了");
                    cm.dispose();
                } else {
					if(selection == 0 && cm.getNX(2) >= price)
						cm.gainNX(2, -price);
					else if(selection == 2 && cm.getRMB() >= priceD)
						cm.gainRMB(-priceD);
					else{//不該發生
						cm.sendOk("發生錯誤!");
						cm.dispose();
						return;
					}
                    cm.setBossLog("當天明星抽獎");
                    cm.setEventCount("累計明星抽獎", 1);
                    if (InsertData) {
						var conn = cm.getConnection();
                        var insert = conn.prepareStatement("INSERT INTO Activity0512 (id,itemid,charid,charName,time) VALUES(?,?,?,?,?)"); // 载入數据
                        insert.setString(1, null); //载入记录ID
                        insert.setString(2, "#t" + item + "#"); //载入记录ID
                        insert.setString(3, cm.getPlayer().getId());
                        insert.setString(4, cm.getPlayer().getName());
                        insert.setString(5, Year + "-" + month + "-" + dates + "");
                        insert.executeUpdate(); //更新
                        insert.close();
						conn.close();
						var time = item[2] == 0?"":("為期" +item[2]+ "天");
						cm.gainGachaponItem(item[0], item[1], "恭喜玩家 " + cm.getChar().getName() + " 人品爆發抽中大獎 " + ii.getName(item) + "。", 1, item[2]);
                        cm.getMap().startMapEffect("恭喜玩家 " + cm.getChar().getName() + " 人品爆發抽中大獎 " + ii.getName(item) + "。", 5120012);
                    }else{
						cm.gainItemPeriod(item[0], item[1], item[2]);
					}
                    status = -1;
                    cm.sendOk("恭喜您從幸運抽獎中獲得 #b#t" + item + "##k.");
                }
            } else {
                cm.sendOk("您沒有足夠的抵用券或贊助點!");//暂時關闭。增加物品中。
                cm.safeDispose();
            }
        } else if (selection == 1) {
			text = "#r-----------------各等級資訊--------------------\r\n";
			text += "#g傳說級人品 : " + rates[0]/10000 +"%\r\n";
			text += "#r尊貴級人品 : " + rates[1]/10000 +"%\r\n";
			text += "#b普通級人品 : " + rates[2]/10000 +"%\r\n";
			text += "#d垃圾級人品 : " + rates[3]/10000 +"%\r\n";
			text += "------------------各物品資訊--------------------\r\n#b";
			text += "#g傳說級:\r\n"
			for(var i in itemListAdvanced){
				text += '#b#v'+itemListAdvanced[i]+'##z'+itemListAdvanced[i]+'# - '+ (Math.round(rates[0]/itemListAdvanced.length)/10000) +'%\r\n';
			}
			text += "\r\n#r尊貴級:\r\n"
			for(var i in itemListGold){
				text += '#b#v'+itemListGold[i]+'##z'+itemListGold[i]+'# - '+ (Math.round(rates[1]/itemListGold.length)/10000) +'%\r\n';
			}
			text += "\r\n#b普通級:\r\n"
			for(var i in itemListSilver){
				text += '#b#v'+itemListSilver[i]+'##z'+itemListSilver[i]+'# - '+ (Math.round(rates[2]/itemListSilver.length)/10000) +'%\r\n';
			}
			text += "\r\n#b垃圾級:\r\n"
			for(var i in itemListNormal){
				text += '#b#v'+itemListNormal[i]+'##z'+itemListNormal[i]+'# - '+ (Math.round(rates[3]/itemListNormal.length)/10000) +'%\r\n';
			}
            cm.sendOk(text);
            cm.dispose();
        } else if (selection == 3) {
			var a=0,b=0,c=0,d=0
			for(i = 0;i < 100;i++){
				var xxx = Math.floor(Math.random() * 1000000);
				if (xxx < rates[0]) {//傳說物品
                    a++;
                } else if (xxx < rates[1]) {//金牌物品
                    b++;
                } else if (xxx < rates[2]) {//銀牌物品
                    c++;
                } else {//垃圾
                    d++;
                }
			}
			text = "#b本次測試 #r100#b 次\r\n\r\n";
			text += "#g傳說級人品 : " + a +"次\r\n";
			text += "#r尊貴級人品 : " + b +"次\r\n";
			text += "#b普通級人品 : " + c +"次\r\n";
			text += "#d垃圾級人品 : " + d +"次\r\n";
            cm.sendOk(text);
            cm.dispose();
        }else {
            cm.sendOk("請聯繫管理員。")
            cm.dispose();
        }
    }
}